<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

<!DOCTYPE HTML>
<html>
  <head>
    <title>模块清单</title>
	<%@ include file="include/common.jsp" %>
  </head>
  <body>
  <%@ include file="include/top.jsp" %>
<div class="hr-mt"></div>
<div>
  	<h2 class="span12">模块发布管理</h2>
  	<div id="" class="span10">
  		<table class="table thead table-bordered table-condensed">
  			<thead>
  				<tr>
  					<th class="cen td-header" rowspan="2">模块ID</th>
  					<th class="cen td-header" rowspan="2">模块名称</th>
  					<th  class="cen td-header" rowspan="2">模块类名</th>
  					<th  class="cen td-header" rowspan="2">模块方法</th>
  					<th  class="cen border-bottom" style="border-bottom: thin;" colspan="${fn:length(publisherDispatchers)}">发布状态</th>
  				</tr>
  				<tr>
  					<c:forEach items="${publisherDispatchers}" var="publisherDispatcher">
  						<th class="cen" >${publisherDispatcher.name}</th>
  					</c:forEach>
  				</tr>
  			</thead>
  			<tbody>
				<c:forEach items="${modules}" var="module">
					<tr>
						<td class="cen" >${module.uid}</td>
						<td class="cen" >${module.name}</td>
						<td class="cen" >${module.moduleClazz.name}</td>
						<td class="cen"  style="font-family: Courser-New;">
						<c:forEach items="${module.methods}" var="method">
						${method.returnType.simpleName} ${method.name}(<c:forEach items="${method.parameterTypes}"
						var="parameterType" varStatus="status">${parameterType.simpleName}<c:if test="${not status.last}">, </c:if></c:forEach>)<br />
						</c:forEach>
						</td>
						<c:forEach items="${module.publishStatuses}" var="publishStatus">
							<td class="cen" >
								<c:if test="${publishStatus.status == 'PUBLISHED'}">
									<input class="status" type="image" src="<%=basePath %>/resources/images/status-green.gif" publisherName="${publishStatus.publisherDispatcher.name}" moduleId="${module.uid}" nextStatus="UNPUBLISHED"> 
								</c:if>
								<c:if test="${publishStatus.status == 'UNPUBLISHED'}">
									<input class="status" type="image" src="<%=basePath %>/resources/images/status-grey.gif" publisherName="${publishStatus.publisherDispatcher.name}"  moduleId="${module.uid}" nextStatus="PUBLISHED"> 
								</c:if>
							</td>
						</c:forEach>
					</tr>
				</c:forEach>
			</tbody>
  		</table>
   	</div>
  </div>
  </body>
  <script type="text/javascript">
  	$(".status").each(function(){
  		var node = $(this);
  		$(this).click(function(){
  			var publisherName = $(this).attr("publisherName");
  			var moduleId = $(this).attr("moduleId");
  			var nextStatus = $(this).attr("nextStatus");
  			$.post('<%=basePath%>/admin/changeStatus.do',
  					{
  						publisherName : publisherName,
		  				moduleId : moduleId,
		  				nextStatus : nextStatus
		  			},
		  			function(result){
		  				if(result == "success") {
		  					if(nextStatus == "UNPUBLISHED") {
		  						node.attr("nextStatus", 'PUBLISHED');
		  						node.attr("src", "<%=basePath%>/resources/images/status-grey.gif");
		  					} else {
		  						node.attr("nextStatus", 'UNPUBLISHED');
		  						node.attr("src", "<%=basePath%>/resources/images/status-green.gif");
		  					}
		  				}
		  			});
  		});
  	});
  </script>
</html>
